package cn.santi.controller;

import cn.santi.domain.*;
import cn.santi.emuns.R;
import cn.santi.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService ss;
    @Autowired
    private ShopImgpathService sis;
    @Autowired
    private boxService bs;
    @Autowired
    private mealService ms;
    @Autowired
    private couponService cs;
    @GetMapping("/quershop")
    public R quershop(String site){
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        wrapper.eq("site",site).eq("state",0);
        return R.ok(ss.list(wrapper));
    }
    //获取门店封面图片
    @GetMapping("/quershopurl")
    public R quershopurl(int id){
        QueryWrapper<ShopImgpath> wrapper = new QueryWrapper<>();
        wrapper.eq("aid",id);
        return R.ok(sis.list(wrapper));
    }
    //搜索门店名称
    @GetMapping("/querbysname")
    public R querbysname(String sname,String site){
        QueryWrapper<Shop> wrapper = new QueryWrapper<>();
        wrapper.like("same",sname).eq("site",site).eq("state",0);
        return R.ok(ss.list(wrapper));
    }
    //根据id查询
    @GetMapping("/querbyidshop")
    public R querbyidshop(int id){
        return R.ok(ss.getById(id));
    }
    //查询门店名称查询包厢
    @GetMapping("/querybox")
    public R querybox(int id){
        QueryWrapper<box> wrapper = new QueryWrapper<>();
        wrapper.eq("sid",id).eq("state",0);
        return R.ok(bs.list(wrapper));
    }
    //根据包厢id查询套餐
    @GetMapping("/querymealbyid")
    public R querymealbyid(int id){
        QueryWrapper<meal> wrapper = new QueryWrapper<>();
        wrapper.eq("bid",id).eq("state",0);
        return R.ok(ms.list(wrapper));
    }
    //查询门店优惠卷
    @GetMapping("/querycouponbyidbid")
    public R querycouponbyidbid(int id){
        QueryWrapper<coupon> wrapper = new QueryWrapper<>();
        wrapper.eq("bid",id).eq("state",0).gt("size",0);
        return R.ok(cs.list(wrapper));
    }
}
